/**
 * 解决了store1存在的action和mutation冗余的问题
 */
import SERVER from '../lib/server2'

export const mapActions = API => API.reduce((pre, serviceName) => {
  pre[serviceName] = ({ commit }, serviceArguments) => {
    return SERVER[serviceName](serviceArguments).then(res => {
      commit(serviceName, res.data)
      return res
    })
  }
}, {})

export const mapMutation = MAP => Object.keys(MAP).reduce((pre, serviceName) => {
  pre[serviceName] = (state, data) => {
    state[MAP[serviceName]] = data
  }
  return pre
}, {})